package com.biostime.springdraw.modules.sys.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.springdraw.common.persistence.Page;
import com.biostime.springdraw.common.persistence.TreeList;
import com.biostime.springdraw.common.service.TreeService;
import com.biostime.springdraw.modules.sys.dao.AreaDao;
import com.biostime.springdraw.modules.sys.entity.Area;

/**
 * 区域Service
 * @author phil
 * @version 2015-11-06
 */
@Service
@Transactional(readOnly = true)
public class AreaService extends TreeService<AreaDao, Area> {

	public List<Area> getParentsTree() {
		List<Area> parents = dao.findList(new Area());
		TreeList<Area> treeList = new TreeList<Area>(parents,"├ ");
		
		return treeList.toList();
	}
	
	@Override
	public Page<Area> findPage(Page<Area> page, Area entity) {
		page.setOrderBy("a.LAYER,a.sort");
		entity.setPage(page);
		
		TreeList<Area> treeList = new TreeList<Area>(dao.findList(entity),"├ ");
		
		page.setList(treeList.toList());
		return page;
	}

	public List<Area> getByParentId(String parentId) {
		
		if(!StringUtils.isEmpty(parentId)){
			Area area = new Area();
			area.setParent(new Area(parentId));
			return dao.findList(area);	
		}
		return new ArrayList<Area>();
	}
	
	
		
	
//	public List<ProvinceDto> apiGetAreaList(){
//		return dao.apiGetAreaList();
//	}
}
